package Socket;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.Socket;
import handler.Receiver;


public class DataToPC extends Thread{
	Thread t;
	Socket socket;
	public DataToPC(Socket socket){
		t = new Thread(this, "DataSenderThread");
		this.socket = socket;
		System.out.println("Child thread: "+t);
		//t.start();
	}
	public void run(){
		Receiver r = new Receiver();
		String dataStr;
		System.out.println("port "+ socket.getPort());
		try{
			BufferedReader fromSocket = new BufferedReader(new InputStreamReader(socket.getInputStream()));
			dataStr = fromSocket.readLine();
			while(!dataStr.equals("DISCONNECT") ||dataStr != null){
				r.receive(dataStr);
				/*if(socket.getPort() == 3000){ //string not formatted before forwarding
					Sender.sendToN7(dataStr);
				}
				else{
					Sender.sendToArduino(dataStr);
				}*/
				dataStr = fromSocket.readLine();
			}
			System.out.println("ended");
			fromSocket.close();
		} 
		catch (Exception e) {
			System.out.println(e.getMessage() + " at "+socket.getPort());
		}
	}
}
